<template>
  <div>
    <!--条件筛选-->
    <TopFilter :list="topFilterList" :cols="3" :collapse="boolean" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <!--操作 -->
    <button-area :style="{ paddingRight : '80px' }">
      <el-button type="primary"  @click="elsa('2')">ElsaPro</el-button>
    </button-area>
    <!-- 列筛选-->
    <FilterTable
      ref="table"
      columnsRef="lhmQueryElsaPro"
      :columns="columns"
      :fetchapi="fetchApi"
      selectionType="single"
      :params="fetchParams"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectData"
    >
    </FilterTable>


  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import dictCode from '@/utils/dictCode';
import { searchRoleByCode } from '@/api/common/empSelect/index';
import { getQueryPart } from '@/api/repair/queryStatistics/queryElsaPro';
import { getUserListSelect } from '@/api/report/repair/repairreport';
import { getfindAllRepairType } from '@/api/repair/business/customer/history';
import { getModel,getSeries } from '@/api/customerRepair/customerCare/insuranceDueRemind/index';
import { getDealerCompanyByCode } from '@/api/common/org/dealerCompany';

export default {
  name: 'LHMQueryElsaPro',
  components: {
  },
  mixins: [dictionary],
  data() {
    this.conf = { add: '新增', delete: '删除', edit: '编辑', show: '显示' };
    return {
      topFilterList: this.createTopFilterList(),
      fetchParams: {},
      visible: false,
      visible1: false,
      boolean:false,
      dialogTitle: '',
      fetchApi: getQueryPart,
      columns: this.createTableColumns(),
      handleType: '',
      formData: {},
      ElsaId:'', // 上传所用的ID
      companyCode: '', // 经销商代码
      tableData: [],
      ids: []
    };
  },
  mounted() {
    // 分页
    this.BaseTable = this.$refs.table.$refs.pageTable;
    this.getRepairType();
    this.initSelect();
    this.querySeries();
    this.getCar();
    this.getDealerCompanyByCode(null);

  },
  methods: {
    async getRepairType(){
      const res = await getfindAllRepairType();
        let list = res.data.map(x => ({ text: x.REPAIR_TYPE_NAME, value: x.REPAIR_TYPE_CODE + '' }));
        this.columns.find(item => item.dataIndex === 'REPAIR_TYPE_CODE').editItems = list; // 维修类型
    },
    // 获取经销商代码
    async getDealerCompanyByCode(param) {
      let res = await getDealerCompanyByCode(param);
      this.companyCode = res.data.companyCode;
    },
    elsa(val){
      if(this.tableData.length>0){
        let roNo = this.tableData[0].RO_NO;// 工单号
        let ORDER_DATE = this.tableData[0].RO_CREATE_DATE;// 开单时间
        this.ElsaId = this.tableData[0].MESSAGE_ID;
        // this.ElsaId ='57144f7f-8042-4c6b-88c4-d031fd020698';
        let vin = this.tableData[0].VIN; // 底盘号
        let f = document.createElement('form'); // 表单
        f.style.display = 'none'; // 显示为none
        f.target = '_blank'; // 打开新页面
        f.action = 'https://portal.cpn.vwg/elsapro/elsaweb/ctr/WorkshopInformationViewAction?VERSION=1.2&MESSAGE_ID='+this.ElsaId+'&ORDER_ID='+roNo+'&SOURCEPROC=PRF-577&ORDER_NO='+roNo+'&ORDER_DATE='+ORDER_DATE.split(" ")[0]+'&COUNTRY=CHN&DEALER_NO='+('1'+this.companyCode.substr(this.companyCode.length-4,this.companyCode.length-1))+'&BRAND=A&PRODUCT_VENDOR_NAME=QiMing&PRODUCT_NAME=DSERP&PRODUCT_VERSION=0.9&PRODUCT_KEY=ElsaPro__23032016001&APP=SP'; // 地址
        f.method = 'post';
        document.body.appendChild(f);
        f.submit();
      }else{
        this.$notify.warning({title:"提示信息",message:"请选择一条工单信息！"})
      }
    },
    async getCar(){
      const car = await getModel();
      console.log(car,'车型11111') // WXFZS
      this.columns.find(x => x.dataIndex === 'MODEL').editItems = car.data.map(x => ({ text: x.MODEL_NAME, value: x.MODEL_ID + '' }));
      // this.columns.find(x => x.dataIndex === 'MODEL').editItems = car.data.map(x => ({ text: x.SERIES_NAME, value: x.SERIES_ID + '' }));

    },
    async initSelect(){
      // 服务顾问
      let testDrive = { role: '' };
      const res = await searchRoleByCode(testDrive);

      this.columns.find(x => x.dataIndex === 'SERVICE_ADVISOR').editItems = res.data.map(x => ({ text: x.employeeName, value: x.userId+''}));
      this.columns.find(x => x.dataIndex === 'SERVICE_CODE').editItems = res.data.map(x => ({ text: x.userCode, value: x.userId+''}));
      this.columns.find(x => x.dataIndex === 'INSPECTOR').editItems = res.data.map(x => ({ text: x.employeeName, value: x.userId+''}));


      },
    async querySeries(){
      // 车系ID翻译
      const car = await getSeries();
      console.log(car,'车系ID翻译');
      this.columns.find(x => x.dataIndex === 'SERIES').editItems = car.data.map(x => ({ text: x.SERIES_CODE, value: x.SERIES_ID + '' }));
      this.columns.find(x => x.dataIndex === 'WXFZS').editItems = car.data.map(x => ({ text: x.SERIES_NAME, value: x.SERIES_ID + '' }));
    },
    createTopFilterList() {
      return [
        {
          type: 'RANGE_DATE',
          label: '送修日期',
          fieldName: 'beginDate|endDate',
          placeholder: '选择日期'
        },
        // {
        //   type: 'SELECT',
        //   label: '委托书类别',
        //   fieldName: 'REPAIR_TYPE_CODE',
        //   initialValue: '',
        //   placeholder: '请选择',
        //   itemList: this.createDictList('9002')
        // },
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
	},
        // {
        //   title: '公司号',
        //   dataIndex: 'GSH',
        //   sorter: true,
        //   filter: true,
        //   showOverflowTooltip: true,
        //   filterType: 'input'

        // },
        {
          title: '委托书编号',
          dataIndex: 'RO_NO',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '维修类别',
          dataIndex: 'REPAIR_TYPE_CODE',
          sorter: true,
          filter: true,
          filterType: 'input',
          editType: 'select',
          showOverflowTooltip: true,
          editItems:[]
        },
        {
          title: '车型',
          dataIndex: 'MODEL',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input',
          editType: 'select',
          editItems:[]
        },
        {
          title: '专属服务顾问代码',
          dataIndex: 'SERVICE_CODE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input',
          editType: 'select',
          editItems:[]
        },
        {
          title: '专属服务顾问名称',
          dataIndex: 'SERVICE_ADVISOR',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input',
          editType: 'select',
          editItems:[]
        },
        {
          title: '牌照号',
          dataIndex: 'LICENSE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '底盘号',
          dataIndex: 'VIN',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '本公司售车',
          dataIndex: 'IS_SELF_COMPANY',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input',
          filterItems: this.createDictList('1004'),
          render: props=>{
            return <span>{this.createDictText(props.row.IS_SELF_COMPANY,'1004')}</span>;
          }
        },
        {
          title: '维修状态',
          dataIndex: 'RO_STATUS',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input',
          filterItems: this.createDictList('8049'),
          render: props => {
            return <span>{this.createDictText(props.row.RO_STATUS, '8049')}</span>;
          }
        },
        {
          title: '预约单号',
          dataIndex: 'BOOKING_ORDER_NO',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '预约类别',
          dataIndex: 'BOOKING_TYPE_CODE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input',
          filterItems: this.createDictList('8055'),
          render: props => {
            return <span>{this.createDictText(props.row.BOOKING_TYPE_CODE, '8055')}</span>;
          }
        },
        {
          title: '车系代码',
          dataIndex: 'SERIES',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input',
          editType: 'select',
          editItems:[]
        },
        {
          title: '车系名称',
          dataIndex: 'WXFZS',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input',
          editType: 'select',
          editItems:[]

        },
        {
          title: '维修时长合计(分钟)',
          dataIndex: 'WTSDYWXSCHJ',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'number'
        },
        {
          title: 'IA',
          dataIndex: 'IA',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: 'JD',
          dataIndex: 'JD',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '送修日期',
          dataIndex: 'RO_CREATE_DATE',
          width: 150,
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'date-range',
          editable: false,
          editType: 'date-picker'
        },
        {
          title: '约定交车日期',
          dataIndex: 'END_TIME_SUPPOSED',
          width: 150,
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'date-range',
          editable: false,
          editType: 'date-picker'
        },
        {
          title: '审核日期',
          dataIndex: 'CHECK_DATE',
          width: 150,
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'date-range',
          editable: false,
          editType: 'date-picker'
        },
        {
          title: '结算日期',
          dataIndex: 'BALANCE_TIME',
          width: 150,
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'date-range',
          editable: false,
          editType: 'date-picker'
        },
        {
          title: '停车车位',
          dataIndex: 'TCCW',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '审核人',
          dataIndex: 'INSPECTOR',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input',
          editType: 'select',
          editItems:[]
        },
        // {
        //   title: '审核人名称',
        //   dataIndex: 'SERVICE_ADVISOR_ASS',
        //   sorter: true,
        //   filter: true,
        //   showOverflowTooltip: true,
        //   filterType: 'input',
        //   editType: 'select',
        //   editItems:[]
        // },
        {
          title: '操作员',
          dataIndex: 'CZY',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input',
          editType: 'select',
          editItems:[]
        },
        {
          title: '行驶里程',
          dataIndex: 'IN_MILEAGE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'number'
        },
        // {
        //   title: '服务顾问代码',
        //   dataIndex: 'FWGWDM',
        //   sorter: true,
        //   filter: true,
        //   showOverflowTooltip: true,
        //   filterType: 'input',
        //   editType: 'select',
        //   editItems:[]
        // },
        {
          title: '车型代码',
          dataIndex: 'CXDM',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '检查员代码',
          dataIndex: 'SERVICE_ADVISOR_CODE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '检察员',
          dataIndex: 'SERVICE_ADVISOR3',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '操作员代码',
          dataIndex: 'CZYDM',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '故障解决',
          dataIndex: 'GZJJ',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: 'FD维护',
          dataIndex: 'FDWH',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: 'FD技术经理处理时间',
          dataIndex: 'FD_DATE',
          width: 150,
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'date-range',
          editable: false,
          editType: 'date-picker'
        },
        {
          title: '技术支持意见',
          dataIndex: 'VTECHNOLOGSUPPORT',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '升级记录编号',
          dataIndex: 'SJJLBH',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '备注',
          dataIndex: 'REMARK',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '购车日期',
          dataIndex: 'SALES_DATE',
          width: 150,
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'date-range',
          editable: false,
          editType: 'date-picker'
        },
        {
          title: '发牌日期',
          dataIndex: 'LICENSE_DATE',
          width: 150,
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'date-range',
          editable: false,
          editType: 'date-picker'
        },
        {
          title: '生产日期',
          dataIndex: 'PRODUCT_DATE',
          width: 150,
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'date-range',
          editable: false,
          editType: 'date-picker'
        },
        {
          title: '查询状态',
          dataIndex: 'CXZT',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '查询描述',
          dataIndex: 'CXMS',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '查询时间',
          dataIndex: 'createdAt1',
          width: 150,
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'date-range',
          editable: false,
          editType: 'date-picker'
        },
        {
          title: '二手车',
          dataIndex: 'SECOND_HAND',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '超期标识',
          dataIndex: 'CQBS',
          width: 120,
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.isValid, '1004')}</span>;
          }
        },
        {
          title: '超期原因',
          dataIndex: 'CQYY',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '预计维修时间',
          dataIndex: 'ESTIMATE_BEGIN_TIME',
          width: 150,
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'date-range',
          editable: false,
          editType: 'date-picker'
        },
      ];
    },
    selectData(val) {
      this.tableData = val;
    },
    addHandle() {
      // 新建
      this.handleType = 'add';
      // this.formData = row;
      this.showHandler();
    },
    editHandle(row) {
      this.handleType = 'edit'; // 编辑

      this.showHandler();
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    // async saveDialog() {
    //   let res = {};
    //   if(this.tableData==null) return
    //     res = await addCustomeRgradeUpdatet({customeRgradeUpdateDTOList:this.tableData });
    //   if (res.resultCode === 200) {
    //     this.closeDialog('refresh');
    //   }
    // },
    showHandler() {
      // 显示
      this.dialogTitle = `查看结算记录`;
      this.visible = true;
    },
    closeHandler(val, type) {
      // 关闭
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  }
};
</script>

<style lang="less" scoped></style>
